package net.lanelife.casino.common.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class StringUtils extends org.apache.commons.lang.StringUtils {
	
	public static List<Integer> toIntegerList(String str, String regex) {
		StringTokenizer t = new StringTokenizer(str, regex);
		List<Integer> l = new ArrayList<Integer>();
		while (t.hasMoreElements()) {
			String s = t.nextToken();
			if (isNotBlank(s)) {
				l.add(Integer.parseInt(s));
			}
		}
		return l;
	}
	
	public static Integer[] toIntegerArray(String str, String regex) {
		List<Integer> list = toIntegerList(str, regex);
		Integer[] arr = new Integer[list.size()];
		return list.toArray(arr);
	}
	
	/**
	 * 校验字符串是否是不以0开头的纯数字
	 * @param str
	 * @return
	 */
	public static boolean isNumeral(String str) {
		return str.matches("^[1-9]\\d*$");
	}
	
	
	public static List<String> partition(String str, int partition) {
		List<String> parts = new ArrayList<String>();
		int len = str.length();
		for (int i = 0; i < len; i += partition) {
			parts.add(str.substring(i, Math.min(len, i + partition)));
		}
		return parts;
	}
	
}
